//
//  UserPowerTableViewCell.m
//  QRMaster
//
//  Created by myApple on 15/8/25.
//  Copyright (c) 2015年 myApple. All rights reserved.
//

#import "UserPowerTableViewCell.h"

@interface UserPowerTableViewCell()
{
    UILabel * userPowerLable;
    UISwitch * userPowerSwitch;
    UIImageView * nextStepImageView;
    UILabel * functionCardLabel;
}

@end

@implementation UserPowerTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self prepareView];
    }
    return self;
}

-(void)prepareView
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    float x = 20;
    float y = 12;
    float width = ScreenWidth - x - 60;
    float height = 20;
    
    userPowerLable = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    userPowerLable.font = [UIFont systemFontOfSize:14.0];
    [self.contentView addSubview:userPowerLable];
    
    
    x = ScreenWidth - 67;
    y = 7;
    width = 51;
    height = 30;
    userPowerSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(x, y, width, height)];
    [userPowerSwitch addTarget:self action:@selector(moveSwitch:) forControlEvents:UIControlEventTouchUpInside];
    userPowerSwitch.on = NO;
    userPowerSwitch.hidden = YES;
    [self.contentView addSubview:userPowerSwitch];
    
    x = UI_SCREEN_WIDTH - 24;
    y = (44 - 12)/2.0;
    width = 8;
    height = 12;
    nextStepImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    nextStepImageView.hidden = YES;
    nextStepImageView.image = [UIImage imageNamed:@"nextIndicate"];
    [self.contentView addSubview:nextStepImageView];
    
    x = UI_SCREEN_WIDTH/ 2.0;
    width = x - 30;
    y = (44 - 20)/2.0;
    height = 20;
    functionCardLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    functionCardLabel.textAlignment = NSTextAlignmentRight;
    functionCardLabel.font = [UIFont systemFontOfSize:14.0];
    [self.contentView addSubview:functionCardLabel];
    
}

-(void)setAuthorityId:(NSString *)authorityId
{
    _authorityId = authorityId;
}

-(void)setStutas:(NSString *)stutas
{
    _stutas = stutas;
    userPowerSwitch.hidden = NO;
    if ([stutas isEqualToString:@"1"]) {
        userPowerSwitch.on = YES;
    }
    else
    {
        userPowerSwitch.on = NO;
    }
}

-(void)setShowNextImage:(BOOL)showNextImage
{
    _showNextImage = showNextImage;
    if (showNextImage) {
        nextStepImageView.hidden = NO;
    }
    else
    {
        nextStepImageView.hidden = YES;
    }
}

-(void)setPowerId:(NSString *)powerId
{
    _powerId = powerId;
}

-(void)setPowerName:(NSString *)powerName
{
    _powerName = powerName;
    userPowerLable.text = powerName;
}

-(void)setSelectedName:(NSString *)selectedName
{
    _selectedName = selectedName;
    functionCardLabel.text = selectedName;
}

-(void)moveSwitch:(UISwitch *)powerSwitch
{
    NSString * status = @"";
    if (powerSwitch.on) {
        status = @"1";
    }
    else
    {
        status = @"0";
    }
    NSMutableDictionary * postDict = [[NSMutableDictionary alloc]init];
    [postDict setValue:status forKey:@"status"];
    [postDict setValue:_powerId forKey:@"powerId"];
    [postDict setValue:_authorityId forKey:@"authorityId"];
    NSMutableArray * postJson = [[NSMutableArray alloc]init];
    [postJson addObject:postDict];
    if (_delegate && [_delegate respondsToSelector:@selector(userPowerCellSendDict:)]) {
        [_delegate userPowerCellSendDict:postJson];
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
